//
//  NNIPhoneNetWorking.m
//  iPhoneX
//
//  Created by liaoyp on 2017/12/11.
//  Copyright © 2017年 liaoyp. All rights reserved.
//

#import "NNIPhoneNetWorking.h"

@implementation NNIPhoneNetWorking
//
///**
// 获取iPhoneX 手机情况
// @param storecode 苹果商品编号
// @param regioncode 所在区编号
// @param stock 是否需要现货
// */
//
//- (void)sendIPhoneXRequestWithStorecode:(NSString *)storecode regioncode:(NSString *)regioncode needStock:(BOOL)stock
//{
//    /* Configure session, choose between:
//     * defaultSessionConfiguration
//     * ephemeralSessionConfiguration
//     * backgroundSessionConfigurationWithIdentifier:
//     And set session-wide properties, such as: HTTPAdditionalHeaders,
//     HTTPCookieAcceptPolicy, requestCachePolicy or timeoutIntervalForRequest.
//     */
//    NSURLSessionConfiguration* sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration];
//    
//    /* Create session, and optionally set a NSURLSessionDelegate. */
//    NSURLSession* session = [NSURLSession sessionWithConfiguration:sessionConfig delegate:nil delegateQueue:nil];
//    
//    /* Create the Request:
//     iPhoneXX (POST http://ir.weip.tech/Home/GetStoreiPhoneList)
//     */
//    
//    NSURL* URL = [NSURL URLWithString:@"http://ir.weip.tech/Home/GetStoreiPhoneList"];
//    NSDictionary* URLParams = @{
//                                @"storecode": @"R485",
//                                @"regioncode": @"HK",
//                                @"onlyshowavailability": @"false",
//                                };
//    URL = NSURLByAppendingQueryParameters(URL, URLParams);
//    NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:URL];
//    request.HTTPMethod = @"POST";
//    
//    /* Start a new Task */
//    NSURLSessionDataTask* task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
//        if (error == nil) {
//            // Success
//            NSLog(@"URL Session Task Succeeded: HTTP %ld", ((NSHTTPURLResponse*)response).statusCode);
//        }
//        else {
//            // Failure
//            NSLog(@"URL Session Task Failed: %@", [error localizedDescription]);
//        }
//    }];
//    [task resume];
//    [session finishTasksAndInvalidate];
//}
//
///*
// * Utils: Add this section before your class implementation
// */
//
///**
// This creates a new query parameters string from the given NSDictionary. For
// example, if the input is @{@"day":@"Tuesday", @"month":@"January"}, the output
// string will be @"day=Tuesday&month=January".
// @param queryParameters The input dictionary.
// @return The created parameters string.
// */
//static NSString* NSStringFromQueryParameters(NSDictionary* queryParameters)
//{
//    NSMutableArray* parts = [NSMutableArray array];
//    [queryParameters enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) {
//        NSString *part = [NSString stringWithFormat: @"%@=%@",
//                          [key stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding],
//                          [value stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]
//                          ];
//        [parts addObject:part];
//    }];
//    return [parts componentsJoinedByString: @"&"];
//}
//
///**
// Creates a new URL by adding the given query parameters.
// @param URL The input URL.
// @param queryParameters The query parameter dictionary to add.
// @return A new NSURL.
// */
//static NSURL* NSURLByAppendingQueryParameters(NSURL* URL, NSDictionary* queryParameters)
//{
//    NSString* URLString = [NSString stringWithFormat:@"%@?%@",
//                           [URL absoluteString],
//                           NSStringFromQueryParameters(queryParameters)
//                           ];
//    return [NSURL URLWithString:URLString];
//}

@end
